// SimpleLogSetting.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>
#include "../CommonFiles/include/ISimpleLoger.h"

#ifdef _DEBUG
	#pragma comment(lib, "../Debug/SimpleLogRecorder.lib")
// 	#pragma comment(lib, "SimpleLogRecorder.lib")
#else
	#pragma comment(lib, "../CommonFiles/lib/SimpleLogRecorder.lib")
#endif

#include "../SimpleLogRecorder/SimpleLoggerControl.h"
using namespace SimpleLogger;

#include <winuser.h>


DWORD __stdcall LogTestProc(LPVOID pData);


int _tmain(int argc, _TCHAR* argv[])
{
	if (STARTRECORDLOG())
	{
		HANDLE hThread[4];
		wchar_t wcLogContent[1024];
		for (int i = 0; i < 4; ++i)
		{
			hThread[i] = ::CreateThread(NULL, 0, &LogTestProc, NULL, 0, NULL);
			wsprintf(wcLogContent, L"Test Log%d", i);
			WRITELOGW(wcLogContent, ll_Fatal, false);
			Sleep(10);
		}
		LoggerSetting loggerSetting;
		loggerSetting.logLevel = ll_Error;
		loggerSetting.logAppender = la_File;
		loggerSetting.uWriteWaitTime = 3000;
		ChangeLoggerSetting(loggerSetting, 60000);
		::WaitForMultipleObjects(4, hThread, TRUE, INFINITE);
		ENDRECORDLOG();
	}
	return 0;
}

DWORD __stdcall LogTestProc(LPVOID pData)
{
// 	ISimpleLogger *pSimpleLogger = (ISimpleLogger *)pData;
	static int sIndex = 0;
	int nIndex = sIndex++;
	LogLevel loglevel = (LogLevel)(nIndex+1);
	wchar_t wcLogContent[1024];
	for (int i = 0; i < 10; ++i)
	{
		wsprintf(wcLogContent, L"Thread%d: Test Log%d", nIndex+1, i);
		WRITELOGW(wcLogContent, loglevel, false);
		Sleep(1000*(i%5));
	}
	return 0;
}
